<?php

/**
 * This is the model class for table "ur_vote".
 *
 * The followings are the available columns in table 'ur_vote':
 * @property integer $id
 * @property integer $bid
 * @property integer $uid
 * @property integer $desire
 * @property integer $rate
 * @property integer $create_datetime
 * @property integer $update_datetime
 *
 * The followings are the available model relations:
 */
class UrVote extends CActiveRecord
{
	public $getReadTag;
	/**
	 * Returns the static model of the specified AR class.
	 * @return UrVote the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'ur_vote';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('bid, uid, desire, rate, create_datetime, update_datetime', 'required'),
			array('bid, uid, desire, rate, create_datetime, update_datetime', 'numerical', 'integerOnly'=>true),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, bid, uid, desire, rate, create_datetime, update_datetime', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'book'=>array(self::BELONGS_TO,'UrBook','bid'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'bid' => 'Bid',
			'uid' => 'Uid',
			'desire' => 'Desire',
			'rate' => 'Rate',
			'create_datetime' => 'Create Datetime',
			'update_datetime' => 'Update Datetime',
		);
	}
	/**
	 * 获取阅读经历
	 * 1 未读 2 在读 3 已读
	 */
	public function getReadTag(){
		$tagName = '';
		switch($this->desire){
			case 1:
			$tagName = '我想读这本书';
			break;
			case 2:
			$tagName = '我正在读这本书';
			break;
			case 3:
			$tagName = '我已经读过这本书';
			break;
			}
		return $tagName;
		}
	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('bid',$this->bid);
		$criteria->compare('uid',$this->uid);
		$criteria->compare('desire',$this->desire);
		$criteria->compare('rate',$this->rate);
		$criteria->compare('create_datetime',$this->create_datetime);
		$criteria->compare('update_datetime',$this->update_datetime);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}
